

import 'package:syria_sports/data/models/error_model.dart';

import '../../core/utils/pref_utils.dart';
import '../../core/utils/show_toast.dart';
import '../apiClient/api_client.dart';
import '../apiClient/api_keys.dart';
import '../models/auth/user.dart';
import '../models/data.dart';
import '../remote/dio_helper.dart';

class PlayerController{

  static Future<Data?> getAllPlayers()async{
    var res = await DioHelper.getData( url: ApiClient.getPlayers, bearerToken: PrefUtils.getToken());

    if(res.statusCode != 200){
      ErrorModel.fromResponse(res);
      return null;
    }
    Data response = Data.fromJson(res.data);
    return response;
  }
  static Future<Data?> getMyPlayers()async{
    var res = await DioHelper.getData( url: ApiClient.getMyPlayers, bearerToken: PrefUtils.getToken() , query: {
      "admins_subscriptions_id":PrefUtils.getAdminsSubscriptionsId(),
    });

    if(res.statusCode != 200){
      ErrorModel.fromResponse(res);
      return null;
    }
    Data response = Data.fromJson(res.data);
    return response;
  }
  static Future<Data?> getPublicPlayers()async{
    var res = await DioHelper.getData( url: ApiClient.getPublicPlayers);

    if(res.statusCode != 200){
      ErrorModel.fromResponse(res);
      return null;
    }
    Data response = Data.fromJson(res.data);
    return response;
  }

  static Future<Data?> deleteById(String id)async{
    var res = await DioHelper.postData(
      url: ApiClient.playerDelete,
      data: {
        'id':id
      },
      bearerToken: PrefUtils.getToken(),
    );
    if(res == null)return null;
    if(res.statusCode != 200){
      ErrorModel.fromResponse(res);
    }else{
      showMessage(res.data[ApiKeys.message]);
      return Data.fromJson(res.data);
    }

    return null;
  }

}